export { requestData, loadMilitaryData, loadGeneralData, loadImportantData };

import axios from "axios";
import useAvtivityStore from "@/store/activity";
const activityStore = useAvtivityStore();

function requestData() {
  loadMilitaryData();
  loadGeneralData();
  loadImportantData();
}

function loadMilitaryData() {
  return new Promise((resolve, reject) => {
    axios
      .get("api/activity_military_load.php")
      .then((response) => {
        if (response.data.status == 0) {
          // console.log('[info]', response.data);
        }
        if (response.data.data) {
          let respond = JSON.parse(JSON.stringify(response.data.data));
          let origion = JSON.parse(
            JSON.stringify(activityStore.militaryStatus)
          );
          resolve({
            status: response.data.status,
            respond,
            origion,
            equal: respond == equal,
          });
          activityStore.militaryStatus = response.data.data;
        } else {
          console.log("[exception]", response.data);
          reject({
            msg: "loadMilitaryDataFailed",
          });
        }
      })
      .catch((error) => {
        console.error(error);
        reject(error);
      });
  });
}

function loadGeneralData() {
  return axios
    .get("api/activity_general_load.php")
    .then((response) => {
      if (response.data.status == 0) {
        // console.log('[info]', response.data);
      }
      if (response.data.data != null) {
        activityStore.generalStatus = response.data.data;
      } else {
        activityStore.generalStatus = [];
        // console.log('[exception]', response.data);
      }
    })
    .catch((error) => console.error(error));
}

function loadImportantData() {
  return axios
    .get("api/activity_important_load.php")
    .then((response) => {
      if (response.data.status == 0) {
        // console.log('[info]', response.data);
      }
      if (response.data.data) {
        activityStore.impotrantStatus = response.data.data;
      } else {
        console.log("[exception]", response.data);
      }
    })
    .catch((error) => console.error(error));
}
